-
Notifications
You must be signed in to change notification settings - Fork 7
Add support for non-string types, LogicalName, ManifestResourceName #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
* Wrote a full .NET fully qualified type name parser using a recursive descent parser * Added support for System.Resources.ResXFileRef resources, which require extra parsing to generate the right code
…to the 2.0 format, fix TypeNameParser to handle assembly names with dots and dashes, add ToCSharp method on ParsedTypeName
…ata on EmbeddedResource items used by the resource compiler to general the internal file name. Without this, we break with any ResX with these values explicitly specified.
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <TargetFramework>net8.0-windows</TargetFramework> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could keep TargetFramework as net8.0 and split the tests into two projects: net8.0 and net8.0-windows. That would let the net8.0 tests run in CI.
| @@ -1,107 +1,126 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <root> | |||
| <!-- | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation was changed from tabs to spaces. Can you please revert this to make the review easier?
| <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" /> | ||
| <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" /> | ||
| <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.1" /> | ||
| <PackageReference Include="sly" Version="3.7.7" PrivateAssets="all" GeneratePathProperty="true" IncludeInPackage="true" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d prefer to avoid third-party dependencies where possible. Are there alternatives to using sly?
Thanks so much for the existing work on this project, it's awesome to get source generator support for ResX files instead of the old crusty VS custom tool!
This PR adds support for several missing features that the old VS custom tool had which are blockers for using this source generator with all the traditional use cases for GUI apps.
<EmbeddedResource>items can have LogicalName or ManifestResourceName specified, which affects the internal resource stream name.There was a big blocker in order to accomplish this, which is that we have to parse .NET fully qualified type names from the ResX file without loading the types themselves (since source analyzers use netstandard2.0 which can't depend on WinForms or other frameworks). Weirdly, the .NET BCL doesn't expose its internal type name parser outside of the type loader! So I had to write a parser from scratch using the grammar specified on MSDN: https://learn.microsoft.com/en-us/dotnet/fundamentals/reflection/specifying-fully-qualified-type-names.
I did add a dependency on a Nuget package called sly which implements a lexer and parser framework I used for parsing type names. This library is also licensed under the MIT license so is compatible with using in this project. I added significant unit testing of the parser so I'm confident it handles just about any resource type anyone could come up with. I can appreciate if fully parsing the type name seems like overkill, but after trying a few simpler approaches and running into issues with common ResX files (some types are fully qualified with the assembly, others aren't, etc.), I figured it would be the only foolproof approach.
Beyond the type name parser, I've added several new test cases to validate that non-string types work properly and LogicalName is respected. I added 3 new diagnostic messages to cover cases where the ResX type is invalid or unsupported.
This would resolve #2 and #10